package com.coda.mapper;

import com.coda.annotation.AutoFill;
import com.coda.entity.AttrKey;
import com.coda.entity.AttrValue;
import com.coda.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AttrMapper {
    /**
     * 新增属性值
     * @param attrValue
     */
    @AutoFill(OperationType.INSERT)
     void insertValue(AttrValue attrValue);

    /**
     * 更新属性值
     * @param attrValue
     */
    @AutoFill(OperationType.UPDATE)
    void updateValue(AttrValue attrValue);

    /**
     * 新增属性名
     * @param attrKey
     */
    @AutoFill(OperationType.INSERT)
    void insertKey(AttrKey attrKey);

    /**
     * 更新属性名
     * @param attrKey
     */
    @AutoFill(OperationType.UPDATE)
    void updateKey(AttrKey attrKey);

    /**
     * 获取所有的属性名key信息
     * @return
     */
    @Select("select * from attr_key")
    List<AttrKey> getKey();

    /**
     * 获取所有属性值
     * @param id
     * @return
     */
    @Select("select * from attr_value where attr_key_id = #{id}")
    List<AttrValue> getValue(Long id);

    /**
     * 根据id删除属性值
     * @param id
     */
    @Delete("delete from attr_value where id = #{id}")
    void deleteValueById(Long id);

    /**
     * 根据id删除名称
     * @param
     */
    @Delete("delete from attr_key where id = #{id}")
    void deleteKeyById(Long id);

    /**
     * 根据key_id删除对应的属性
     * @param attrKeyId
     */
    @Delete("delete from attr_value where attr_key_id = #{attrKeyId}")
    void deleteValueByKeyId(Long attrKeyId);
}
